package org.lhh.server.pojo.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.pentaho.di.repository.RepositoryElementMetaInterface;
import org.pentaho.di.trans.TransMeta;

import java.util.Date;

/**
 * @author 辉仔
 * @since 2019-06-16
 */
@Data
public class TransVo {

    private String id;

    private String name;

    private String transName;

    private String pid;

    private String updateBy;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    private boolean edit;

    private int status;

    public static TransVo encode(TransMeta transMeta) {
        TransVo transVo = new TransVo();
        transVo.setId(transMeta.getObjectId().getId());
        transVo.setName(transMeta.getName());
        transVo.setTransName(transMeta.getDescription());
        transVo.setPid(transMeta.getRepositoryDirectory().getObjectId().getId());
        transVo.setUpdateBy(transMeta.getModifiedUser());
        transVo.setUpdateTime(transMeta.getModifiedDate());
        return transVo;
    }

    public static TransVo encode(RepositoryElementMetaInterface repositoryElementMetaInterface) {
        TransVo transVo = new TransVo();
        transVo.setId(repositoryElementMetaInterface.getObjectId().getId());
        transVo.setName(repositoryElementMetaInterface.getName());
        transVo.setTransName(repositoryElementMetaInterface.getDescription());
        transVo.setPid(repositoryElementMetaInterface.getRepositoryDirectory().getObjectId().getId());
        transVo.setUpdateBy(repositoryElementMetaInterface.getModifiedUser());
        transVo.setUpdateTime(repositoryElementMetaInterface.getModifiedDate());
        return transVo;
    }
}
